﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfSampleDatagridDisplay
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            InitializeComponent();
            ObservableCollection<Member> memberData = new ObservableCollection<Member>()
             {
                 new Member(){DepartmetId = "Dp01",EmployeeId = "EP0011" ,Name = "Joe1",Address = "Street 1",Email = new Uri("mailto:Joe1@school.com")},
                 new Member(){DepartmetId = "Dp02",EmployeeId = "EP0012" ,Name = "Joe2",Address = "Street 2",Email = new Uri("mailto:Joe2@school.com")},
                 new Member(){DepartmetId = "Dp03",EmployeeId = "EP0013" ,Name = "Joe3",Address = "Street 3",Email = new Uri("mailto:Joe3@school.com")},
                 new Member(){DepartmetId = "Dp04",EmployeeId = "EP0014" ,Name = "Joe4",Address = "Street 4",Email = new Uri("mailto:Joe4@school.com")}
             };
            dataGrid.DataContext = memberData;
        }
        private void dataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            string str = "";
            if (dataGrid.SelectedItems.Count > 0)
            {
                Member member = new Member();
                foreach (var obj in dataGrid.SelectedItems)
                {
                    member = obj as Member;
                    str += "DepartmetId : " + member.DepartmetId + "   EmployeeId:" + member.EmployeeId + "  Name:" + member.Name + "  Address:" + member.Address + "  Email:" + member.Email + "\n";
                }
            }
            else
            {

            }
            myTxt.Text = str;
        }
    }
}
